<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        #nav {
            width: 415px;
            height: 42px;
            margin: 100px auto;
            position: relative;
        }
        .list ul {
            overflow: hidden;
            position: absolute;
            z-index: 5;
        }
        .list ul li {
            float: left;
            width: 83px;
            height: 42px;
        }
        .list ul li a {
            display: block;
            text-align: center;
            line-height: 42px;
            text-decoration: none;
        }
        #nav img {
            position: absolute;
            left: 0;
            top: 0;
            z-index: 0;
        }
    </style>
</head>
<body>
    <nav id="nav">
        <div class="list">
            <ul>
                <li><a href="javascript:;">你好</a></li>
                <li><a href="javascript:;">你好</a></li>
                <li><a href="javascript:;">你好</a></li>
                <li><a href="javascript:;">你好</a></li>
                <li><a href="javascript:;">你好</a></li>
            </ul>
        </div>
        <img src="cloud.gif" alt="" id='cloud'>
    </nav>
    <script src='../common.js'></script>
    <script>
        //获取元素
        var aList = document.getElementsByTagName('a');
        var cloud = document.getElementById('cloud');

        //注册事件
        //碰到a时,cloud,会移动过来,移开会回到主人位置,当点击时,cloud,重新选主人
        var owner = aList[0].offsetLeft; //默认主人
        console.log(owner);
        
        for(var i = 0; i < aList.length; i++) {
            var a = aList[i];
            a.onmouseover = function() {
                animationAll(cloud,{left: this.offsetLeft})
            }
            a.onmouseout = function() {
                animationAll(cloud,{left: owner})
            }
            a.onclick = function() {
                owner = this.offsetLeft;
            }
        }
    </script>
</body>
</html>